
var mess=[];
var manAddr ={
	init : function(){
		app.ajax(
			'/Goods/Cart/address_list',
			null,
			function(res){
				if(res.code == 200){
					app.tpl($('.addr-man'),'tpl-addr-man',res);
					var list = res.address_list;
					for(var i=0;i<list.length;i++){
						var data={
							id : list[i].id,
							idcard : list[i].idcard,
							uname : list[i].name,
							tel  : list[i].mobile,
							area : list[i].area,
							isdefault : list[i].is_default,
							prov      : list[i].provinceid,
							city      : list[i].cityid,
							addr	:  list[i].address,
							areaid  :  list[i].areaid,
							is_default :list[i].is_default
						}
						mess.push(data);
					}
				}else{
					layer.msg('网络繁忙，请稍候再试');
				}
			}
		);
	}
}
	footer.init();
	header.init('地址管理');
	manAddr.init();
window.onload = function(){
	$('body').on('click','.addAddr-btn',function(){
		app.open('user.setAddr.html','setAddr',{title:'新增地址',type:1},window.location.href,document.body.scrollTop);
	});
	
	$('body').on('click','.addr-list .edit',function(){
		var index = $(this).parents('.addr-list').index('.addr-man .addr-list');
		var data = mess[index];
		app.open('user.setAddr.html','setAddr',{title:'修改地址',type:2,mess:data},window.location.href,document.body.scrollTop);
	});
	
	$('body').on('click','.addr-list .dele',function(){
		var ids = $(this).attr('data-id');
		var data={
			id : ids
		};
		var t=$(this);
		layer.open({
			content:'确定要删除该地址吗？',
			btn:['确定','取消'],
			shadeClose:false,
			yes:function(index){
				layer.close(index);
				app.ajax(
					'/Member/Setting/address_del',
					data,function(res){
						if(res.code == 200){
							layer.msg('删除成功');
							t.parents('.addr-list').remove();
						}
				});
			}
		});
		
	});
}
